﻿Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Excel

''' <summary>
''' Implémentation abstraite d'un gestionnaire EXCEL
''' </summary>
''' <remarks></remarks>
Public MustInherit Class AbstractGestionExcel
    Implements IGestionExcel

#Region "Implémentation des interfaces utilisées dans les méthodes de la classe"
    Protected _implTableau As IImplTableau
#End Region

#Region "Déclarations des variables de classe"

    Private _ApplicationXL As Microsoft.Office.Interop.Excel.Application
    Private _LesWorkBooks As Workbooks
    Private _MonClasseur As _Workbook
    Private _MaFeuille As _Worksheet
    Protected Friend _MonRange As Range
    Private _MonGraphique As _Chart
    Private M As Object = System.Reflection.Missing.Value
    Private _NomFichier As String

#End Region

    ''' <summary>
    ''' Constructeur
    ''' </summary>
    ''' <param name="Succes"></param>
    ''' <remarks></remarks>
    Public Sub New(ByRef Succes As Boolean)
        Try
            _ApplicationXL = New Microsoft.Office.Interop.Excel.Application()
            _implTableau = New ImplTableauDefaut()
            Succes = True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Succes = False
        End Try
    End Sub

    ''' <summary>
    ''' Plage de cellules active
    ''' </summary>
    ''' <remarks></remarks>
    Public Function getActiveRange() As Range Implements IGestionExcel.GetActiveRange
        Return _MonRange
    End Function

    ''' <summary>
    ''' Interface représentant le dessin d'un tableau
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub setImplTableau(ByVal implTableau As IImplTableau) Implements IGestionExcel.setImplTableau
        _implTableau = implTableau
    End Sub

    ''' <summary>
    ''' Créer un nouveau classeur Excel
    ''' </summary>
    ''' <remarks></remarks>
    Public Function CreerNouveauFichier(ByVal NouveauNomFeuille As String) As Boolean _
        Implements IGestionExcel.CreerNouveauFichier
        Try
            _MonClasseur = DirectCast((_ApplicationXL.Workbooks.Add(M)), _Workbook)
            _MaFeuille = DirectCast(_MonClasseur.ActiveSheet, _Worksheet)
            _MaFeuille.Name = NouveauNomFeuille
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function

    ''' <summary>
    ''' Enregistrer Sous
    ''' </summary>
    ''' <remarks></remarks>
    Public Function EnregistrerSous(ByVal NomFichier As String) As Boolean _
        Implements IGestionExcel.EnregistrerSous
        _NomFichier = NomFichier
        Try
            Dim FileName As Object = DirectCast(NomFichier, Object)
            _MonClasseur.SaveAs(FileName, M, M, M, M, M, _
              XlSaveAsAccessMode.xlNoChange, M, M, M, M, M)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function EnregistrerSousFeuilleCalculXML(ByVal NomFichier As String) As Boolean _
        Implements IGestionExcel.EnregistrerSousFeuilleCalculXML
        _NomFichier = NomFichier
        Try
            Dim FileName As Object = DirectCast(NomFichier, Object)
            _MonClasseur.SaveAs(FileName, XlFileFormat.xlXMLSpreadsheet, M, M, DirectCast(False, Object), DirectCast(False, Object), _
              XlSaveAsAccessMode.xlNoChange, M, M, M, M, M)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function OuvrirFichierExistant(ByVal NomFichier As String, ByVal NomFeuille As String) As Boolean _
        Implements IGestionExcel.OuvrirFichierExistant
        Try
            _LesWorkBooks = _ApplicationXL.Workbooks
            _MonClasseur = _LesWorkBooks.Open(NomFichier, M, M, M, M, M, _
              M, M, M, M, M, M, _
              M, M, M)
            _MaFeuille = DirectCast(_MonClasseur.Sheets(NomFeuille), _Worksheet)
            _MaFeuille.Activate()
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function Sauver() As Boolean _
        Implements IGestionExcel.Sauver
        Try
            _MonClasseur.Save()
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub FermerWoorkBook() _
        Implements IGestionExcel.FermerWoorkBook
        Sauver()
        If Not _MaFeuille Is Nothing Then
            System.Runtime.InteropServices.Marshal.ReleaseComObject(_MaFeuille)
            _MaFeuille = Nothing
        End If
        If Not _MonClasseur Is Nothing Then
            _MonClasseur.Close(True, _NomFichier, M)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(_MonClasseur)
            _MonClasseur = Nothing
        End If
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub QuitterXl() Implements IGestionExcel.QuitterXl
        FermerWoorkBook()
        If Not _LesWorkBooks Is Nothing Then
            System.Runtime.InteropServices.Marshal.ReleaseComObject(_LesWorkBooks)
            _LesWorkBooks = Nothing
        End If
        If Not _ApplicationXL Is Nothing Then
            _ApplicationXL.Quit()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(_ApplicationXL)
            _ApplicationXL = Nothing
        End If
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub EcrireLigne(ByVal LigneAEcrire As String(), ByVal NumeroLigne As Integer) _
        Implements IGestionExcel.EcrireLigne
        Dim _Col As Integer = 1
        For Each Elements As String In LigneAEcrire
            _MaFeuille.Cells(NumeroLigne, _Col) = Elements
            System.Math.Max(System.Threading.Interlocked.Increment(_Col), _Col - 1)
        Next
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub EcrireLigne(ByVal LigneAEcrire As Object(), ByVal NumeroLigne As Integer) _
        Implements IGestionExcel.EcrireLigne
        Dim _Col As Integer = 1
        For Each Elements As Object In LigneAEcrire
            _MaFeuille.Cells(NumeroLigne, _Col) = Elements
            System.Math.Max(System.Threading.Interlocked.Increment(_Col), _Col - 1)
        Next
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub EcrireCellule(ByVal Valeur As Object, ByVal A1 As String) _
        Implements IGestionExcel.EcrireCellule
        Dim ligne As Integer
        Dim colonne As Integer
        Me.AdresseCellL1C1(A1, ligne, colonne)
        Me.EcrireCellule(Valeur, ligne, colonne)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub EcrireCellule(ByVal Valeur As Object, ByVal NumeroLigne As Integer, _
                             ByVal NumeroColonne As Integer) _
                             Implements IGestionExcel.EcrireCellule
        _MaFeuille.Cells(NumeroLigne, NumeroColonne) = Valeur
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub EcrireTableau(ByVal Valeurs As Object(,)) Implements IGestionExcel.EcrireTableau
        _MonRange.Value2 = Valeurs
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub creerNouvelleFeuille(ByVal nomFeuille As String) Implements IGestionExcel.CreerNouvelleFeuille
        Try
            _MaFeuille = DirectCast(_MonClasseur.Worksheets.Add(), _Worksheet)
            _MaFeuille.Name = nomFeuille
            _MaFeuille.Activate()
        Catch e As Exception
            MessageBox.Show(e.Message)
        End Try
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function ChangerDeFeuilleActive(ByVal NumeroFeuille As Integer, _
                                           ByVal NouveauNom As String) As Boolean _
                                           Implements IGestionExcel.ChangerDeFeuilleActive
        Try
            _MaFeuille = DirectCast(_MonClasseur.Sheets(NumeroFeuille), _Worksheet)
            _MaFeuille.Name = NouveauNom
            _MaFeuille.Activate()
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function ChangerDeFeuilleActive(ByVal NomFeuille As String) As Boolean _
        Implements IGestionExcel.ChangerDeFeuilleActive
        Try
            _MaFeuille = DirectCast(_MonClasseur.Sheets(NomFeuille), _Worksheet)
            _MaFeuille.Activate()
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function ChangerDeFeuilleActive(ByVal NumeroFeuille As Integer) As Boolean _
        Implements IGestionExcel.ChangerDeFeuilleActive
        Try
            _MaFeuille = DirectCast(_MonClasseur.Sheets(NumeroFeuille), _Worksheet)
            _MaFeuille.Activate()
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SelectionRange(ByVal CellTypA1 As String, ByVal CellTypB2 As String) _
        Implements IGestionExcel.SelectionRange
        _MonRange = _MaFeuille.Range(CellTypA1, CellTypB2)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SelectionRange(ByVal numLigneHautGauche As Integer, _
                              ByVal numColHautGauche As Integer, _
                              ByVal numLigneBasDroite As Integer, _
                              ByVal numColBasDroite As Integer) _
                              Implements IGestionExcel.SelectionRange
        _MonRange = _MaFeuille.Range(AdresseCellTypeA1(numLigneHautGauche, numColHautGauche), _
                                     AdresseCellTypeA1(numLigneBasDroite, numColBasDroite))
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SelectionColonne(ByVal Colonne As String) _
        Implements IGestionExcel.SelectionColonne
        Dim MaColonne As String = String.Format("{0}:{1}", Colonne, Colonne)
        _MonRange = _MaFeuille.Range(MaColonne, M)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SelectionColonne(ByVal numColonne As Integer) Implements IGestionExcel.SelectionColonne
        Dim A1colonne As String = AdresseCellTypeA1(1, numColonne)
        A1colonne = Microsoft.VisualBasic.Left(A1colonne, Len(A1colonne) - 1)
        SelectionColonne(A1colonne)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SelectionLigne(ByVal Ligne As Integer) _
        Implements IGestionExcel.SelectionLigne
        Dim MaLigne As String = String.Format("{0}:{1}", Ligne, Ligne)
        _MonRange = _MaFeuille.Range(MaLigne, M)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub SupprimerRange(ByVal SensDecallageDonnees As XlDeleteShiftDirection)
        _MonRange.Delete(SensDecallageDonnees)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub HauteurLigne(ByVal numLigne As Integer, ByVal hauteur As Integer) Implements IGestionExcel.HauteurLigne
        '_MaFeuille.Rows(numLigne).height = hauteur
        SelectionLigne(numLigne)
        _MonRange.RowHeight = hauteur
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub LargeurColonne(ByVal numColonne As Integer, ByVal largeur As Integer) Implements IGestionExcel.LargeurColonne
        '_MaFeuille.Columns(numColonne).Width = largeur
        '_MonRange.
        SelectionColonne(numColonne)
        _MonRange.ColumnWidth = largeur
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AfficherGridLines(ByVal b As Boolean) Implements IGestionExcel.AfficherGridLines
        _MaFeuille.Application.ActiveWindow.DisplayGridlines = b
    End Sub

    Public Property DisplayAlert As Boolean
        Get
            Return _ApplicationXL.DisplayAlerts
        End Get
        Set(ByVal value As Boolean)
            _ApplicationXL.DisplayAlerts = value
        End Set
    End Property

    Public Property CalculateBeforeSave As Boolean
        Get
            Return _ApplicationXL.CalculateBeforeSave
        End Get
        Set(ByVal value As Boolean)
            _ApplicationXL.CalculateBeforeSave = value
        End Set
    End Property

    Public Property Calculation As XlCalculation
        Get
            Return _ApplicationXL.Calculation
        End Get
        Set(ByVal value As XlCalculation)
            _ApplicationXL.Calculation = value
        End Set
    End Property


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub colorieRange(ByVal c As System.Drawing.Color) Implements IGestionExcel.ColorieRange
        '_MonRange.Interior.Color = RVBtoVBhexa(c.R, c.G, c.B)
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub changeCouleurTexteRange(ByVal c As System.Drawing.Color) Implements IGestionExcel.ChangeCouleurTexteRange
        '_MonRange.Font.Color = RVBtoVBhexa(c.R, c.G, c.B)
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function AdresseCellTypeA1(ByVal L1C1 As String) As String _
        Implements IGestionExcel.AdresseCellTypeA1
        Dim Ligne As Integer = 0
        Dim Colonne As Integer = 0
        Return Me.AdresseCellTypeA1(L1C1, Ligne, Colonne)
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function AdresseCellTypeA1(ByVal L1C1 As String, ByRef Ligne As Integer, _
                                      ByRef Colonne As Integer) As String _
                                      Implements IGestionExcel.AdresseCellTypeA1
        Dim index As Integer = L1C1.IndexOf("C")
        Ligne = Convert.ToInt16(L1C1.Substring(1, index - 1))
        Colonne = Convert.ToInt16(L1C1.Substring(index + 1))
        Return Me.AdresseCellTypeA1(Ligne, Colonne)
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function AdresseCellTypeA1(ByVal Ligne As Integer, _
                                      ByVal Colonne As Integer) As String _
                                      Implements IGestionExcel.AdresseCellTypeA1
        If Ligne < 1 OrElse Colonne < 1 Then
            Return Nothing
        Else
            If Colonne < 27 Then
                Dim Lettre As New Char()
                Lettre = Convert.ToChar(Colonne + 64)
                Return String.Format("{0}{1}", Lettre.ToString(), Ligne)
            Else
                Dim Lettre2 As Integer
                Dim Lettre1 As Integer = Math.DivRem(Colonne, 26, Lettre2)
                Dim Lettre11 As New Char()
                Lettre11 = Convert.ToChar(Lettre1 + 64)
                Dim Lettre22 As New Char()
                Lettre22 = Convert.ToChar(Lettre2 + 64)
                Return String.Format("{0}{1}{2}", Lettre11.ToString(), Lettre22.ToString(), Ligne)
            End If
        End If
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function AdresseCellL1C1(ByVal A1 As String) As String _
        Implements IGestionExcel.AdresseCellL1C1
        Dim toto As Integer
        Dim tutu As Integer
        Return Me.AdresseCellL1C1(A1, toto, tutu)
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function AdresseCellL1C1(ByVal A1 As String, ByRef NumeroLigne As Integer, _
                                    ByRef NumeroColonne As Integer) As String _
                                    Implements IGestionExcel.AdresseCellL1C1
        Dim Lettre As Integer() = {0, 0}
        NumeroLigne = 0
        NumeroColonne = 0
        Dim i As Integer = 0
        While i < A1.Length
            Dim Car As Char = A1(i)
            If (Asc(Car) > 64) AndAlso (Asc(Car) < 91) Then
                Lettre(i) = Convert.ToInt32(Car) - 64
            Else
                NumeroLigne = Convert.ToInt32(A1.Substring(i))
                i = A1.Length
            End If
            System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
        End While
        If Lettre(1) = 0 Then
            NumeroColonne = Lettre(0)
        Else
            NumeroColonne = 26 * Lettre(0) + Lettre(1)
        End If
        Return String.Format("L{0}C{1}", NumeroLigne.ToString(), NumeroColonne.ToString())
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub EncradrementRange(ByVal Encadrement As TypeEncadrement) _
        Implements IGestionExcel.EncradrementRange
        Select Case Encadrement
            Case TypeEncadrement.ToutesCellulesFin
                _MonRange.Borders.LineStyle = XlLineStyle.xlContinuous
            Case TypeEncadrement.ToutesCellulesMoyen
                _MonRange.Borders.LineStyle = XlLineStyle.xlContinuous
                _MonRange.Borders.Weight = XlBorderWeight.xlMedium
            Case TypeEncadrement.Aucun
                _MonRange.Borders.LineStyle = XlLineStyle.xlLineStyleNone
            Case TypeEncadrement.ExtérieurRangeFin
                _MonRange.BorderAround(XlLineStyle.xlContinuous, XlBorderWeight.xlThin, XlColorIndex.xlColorIndexAutomatic, M)
            Case TypeEncadrement.ExtérieurRangeMoyen
                _MonRange.BorderAround(XlLineStyle.xlContinuous, XlBorderWeight.xlMedium, XlColorIndex.xlColorIndexAutomatic, M)
        End Select
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub CreerGraphique(ByVal NomFeuilleDonnees As String, _
                              ByVal CellHautGauche As String, _
                              ByVal NbreLignes As Integer, _
                              ByVal NbreColonnes As Integer, _
                              ByVal Titre As String, ByVal CellSerie As String, _
                              ByVal NomFeuille As String) _
                              Implements IGestionExcel.CreerGraphique
        _MonGraphique = DirectCast(_MonClasseur.Sheets.Add(_MonClasseur.Sheets(1), M, 1, XlWBATemplate.xlWBATChart), _Chart)
        _MonGraphique.ChartType = XlChartType.xlXYScatterLinesNoMarkers
        _MonGraphique.Name = NomFeuille
        _MaFeuille = DirectCast(_MonClasseur.Sheets(NomFeuilleDonnees), _Worksheet)
        _MonRange = _MaFeuille.Range(CellHautGauche, CellSerie).get_Resize(NbreLignes + 1, NbreColonnes)
        _MonGraphique.SetSourceData(_MonRange, XlRowCol.xlColumns)
        If _MonGraphique.HasTitle Then
            _MonGraphique.ChartTitle.Text = Titre
        End If
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AjouterCourbe(ByVal Nom As String, _
                             ByVal NomFeuilleDonnee As String, _
                             ByVal CelluleHautX As String, _
                             ByVal CelluleBasX As String, _
                             ByVal CelluleHautY As String, _
                             ByVal CelluleBasY As String) _
                             Implements IGestionExcel.AjouterCourbe
        Dim _MesSeries As SeriesCollection = (DirectCast(_MonGraphique.SeriesCollection(M), SeriesCollection))
        Dim _MaSerie As Series = _MesSeries.NewSeries()
        _MaSerie.Name = Nom
        Dim PlageDonneesX As String = String.Format("='{0}'!${1}${2}:${3}${4}", NomFeuilleDonnee, CelluleHautX(0), CelluleHautX(1), CelluleBasX(0), CelluleBasX(1))
        Dim PlageDonneesY As String = String.Format("='{0}'!${1}${2}:${3}${4}", NomFeuilleDonnee, CelluleHautY(0), CelluleHautY(1), CelluleBasY(0), CelluleBasY(1))
        _MaSerie.XValues = PlageDonneesX
        _MaSerie.Values = PlageDonneesY
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function Chercher(ByVal TexteATrouver As String) As String _
        Implements IGestionExcel.Chercher
        Dim What As Object = DirectCast(TexteATrouver, Object)
        If _MonRange Is Nothing Then
            Me.SelectionRange("A1", "A1")
        End If
        _MonRange = _MaFeuille.Cells.Find(What, _MonRange, M, XlLookAt.xlPart, XlSearchOrder.xlByColumns, XlSearchDirection.xlNext, _
          DirectCast(False, Object), M, DirectCast(False, Object))
        If _MonRange Is Nothing Then
            Return "Recherche infructeuse"
        Else
            _MonRange.Activate()
            Return String.Format("L{0}C{1}", _MonRange.Row.ToString(), _MonRange.Column.ToString())
        End If
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function Chercher(ByVal TexteATrouver As String, ByRef Contenu As String) As String _
        Implements IGestionExcel.Chercher
        Dim Ligne As Integer = 0
        Dim Colonne As Integer = 0
        Dim Cellule As String = Me.Chercher(TexteATrouver)
        Contenu = Me.LireCellule(Cellule, Ligne, Colonne)
        Return Cellule
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function LireCellule(ByVal AdresseA1 As String) As String _
        Implements IGestionExcel.LireCellule
        Me.SelectionRange(AdresseA1, AdresseA1)
        If _MonRange.Value2 Is Nothing Then Return "" Else Return DirectCast(_MonRange.Value2.ToString(), String)
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function LireCellule(ByVal AdresseL1C1 As String, _
                                ByRef NumeroLigne As Integer, _
                                ByRef NumeroColonne As Integer) As String _
                                Implements IGestionExcel.LireCellule
        Dim AdresseA1 As String = Me.AdresseCellTypeA1(AdresseL1C1, NumeroLigne, NumeroColonne)
        Return Me.LireCellule(AdresseA1)
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function LireCellule(ByVal NumeroLigne As Integer, _
                                ByVal NumeroColonne As Integer) As String _
                                Implements IGestionExcel.LireCellule
        Dim AdresseA1 As String = Me.AdresseCellTypeA1(NumeroLigne, NumeroColonne)
        Return Me.LireCellule(AdresseA1)
    End Function

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function ProtegerFeuille() As Boolean _
        Implements IGestionExcel.ProtegerFeuille
        Dim Vrai As Object = DirectCast(True, Object)
        Dim Faux As Object = DirectCast(False, Object)
        Try
            _MaFeuille.Protect(M, Vrai, Vrai, Vrai, M, M, _
              M, M, M, M, M, M, _
              M, M, M, M)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function ProtegerFeuille(ByVal MotDePasse As String) As Boolean _
        Implements IGestionExcel.ProtegerFeuille
        Dim Vrai As Object = DirectCast(True, Object)
        Dim Faux As Object = DirectCast(False, Object)
        Dim Password As Object = DirectCast(MotDePasse, Object)
        Try
            _MaFeuille.Protect(Password, Vrai, Vrai, Vrai, M, M, _
              M, M, M, M, M, M, _
              M, M, M, M)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function OterProtectionFeuille() As Boolean _
        Implements IGestionExcel.OterProtectionFeuille
        Try
            _MaFeuille.Unprotect(M)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function OterProtectionFeuille(ByVal MotDePasse As String) As Boolean _
        Implements IGestionExcel.OterProtectionFeuille
        Dim Password As Object = DirectCast(MotDePasse, Object)
        Try
            _MaFeuille.Unprotect(MotDePasse)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function ProtegerClasseur(ByVal [Structure] As Boolean, _
                                     ByVal Fenetres As Boolean) As Boolean _
                                     Implements IGestionExcel.ProtegerClasseur
        Dim _Structure As Object = DirectCast([Structure], Object)
        Dim _Fenetres As Object = DirectCast(Fenetres, Object)
        Try
            _MonClasseur.Protect(M, _Structure, _Fenetres)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function ProtegerClasseur(ByVal MotDePasse As String, _
                                     ByVal [Structure] As Boolean, _
                                     ByVal Fenetres As Boolean) As Boolean _
                                     Implements IGestionExcel.ProtegerClasseur
        Dim Password As Object = DirectCast(MotDePasse, Object)
        Dim _Structure As Object = DirectCast([Structure], Object)
        Dim _Fenetres As Object = DirectCast(Fenetres, Object)
        Try
            _MonClasseur.Protect(M, _Structure, _Fenetres)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function OterProtectionClasseur() As Boolean _
        Implements IGestionExcel.OterProtectionClasseur
        Try
            _MonClasseur.Unprotect(M)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function OterProtectionClasseur(ByVal MotDePasse As String) As Boolean _
        Implements IGestionExcel.OterProtectionClasseur
        Dim Password As Object = DirectCast(MotDePasse, Object)
        Try
            _MonClasseur.Unprotect(MotDePasse)
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message)
            Return False
        End Try
    End Function

    Public Property Visible As Boolean
        Get
            Return _ApplicationXL.Visible
        End Get
        Set(ByVal value As Boolean)
            _ApplicationXL.Visible = value
        End Set
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Function creerTableau(ByVal titre As String, _
                                 ByVal tab As System.Data.DataTable, _
                                 ByVal numeroLigneHautGauche As Integer, _
                                 ByVal numeroColonneHautGauche As Integer) As Boolean _
                                 Implements IGestionExcel.creerTableau

        _implTableau.DessineTableau(Me, titre, tab, _
                                    numeroLigneHautGauche, _
                                    numeroColonneHautGauche)

        Return True
    End Function

End Class
